package com.mmlc.inter;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;

/**
 * @author king
 * @function FragmentActivity抽象基类
 * @date 2016-1-13下午6:30:53
 */
public abstract class InterFragmentActivity extends FragmentActivity implements
        OnClickListener {
    protected long lasttime = 0;

    protected boolean avoid() {
        return avoid(700);
    }

    protected boolean avoid(long period) {
        long currenttime = System.currentTimeMillis();
        if (currenttime - lasttime <= period) {
            if (context != null) {

            }
            return true;
        } else {
            lasttime = currenttime;
        }
        return false;
    }

    protected String TAG;
    protected Activity activity;
    protected Context context;
    protected String userId;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // App.addActivity(this);
        // overridePendingTransition(R.anim.act_leftin, R.anim.act_leftout);
        setContentView(initContentView());

        TAG = this.getClass().getSimpleName();
        activity = this;
        context = getApplicationContext();
        lasttime = System.currentTimeMillis();

        initExtra();
        initView();
        initInfo();
        initEvent();
        registerReceiver();

        startPushWork();
    }

    protected void startPushWork() {
        if (userId == null || "".equals(userId) || "null".equals(userId)) {
            return;
        }
    }

    /**
     * 绑定布局
     *
     * @return layoutResID
     */
    protected abstract int initContentView();

    /**
     * 获取参数
     */
    protected void initExtra() {
    }

    /**
     * 初始化控�?
     */
    protected abstract void initView();

    /**
     * 加载数据
     */
    protected void initInfo() {
    }

    /**
     * 注册事件
     */
    protected void initEvent() {
    }

    @Override
    public void onClick(View v) {
        if (avoid())
            return;
    }

    /**
     * 注册广播接收�?
     */
    protected void registerReceiver() {
    }

    @Override
    public void finish() {
        super.finish();
        // overridePendingTransition(R.anim.act_rightin, R.anim.act_rightout);
    }

}
